//
//  Thirdlub_routeCollectionViewCell.m
//  Project_B
//
//  Created by dllo on 15/11/26.
//  Copyright © 2015年 张闯. All rights reserved.
//

#import "Thirdlub_routeCollectionViewCell.h"
#import "Thirdlub_routeTableViewCell.h"
#import "AFNetworkHandler.h"
#import "UIImageView+WebCache.h"

@interface Thirdlub_routeCollectionViewCell () <UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *table;

@end

@implementation Thirdlub_routeCollectionViewCell

#pragma mark - 初始化
- (instancetype)initWithFrame:(CGRect)frame
{
    
    self = [super initWithFrame:frame];
    if (self) {
        self.table = [[UITableView alloc] initWithFrame:self.contentView.frame style:(UITableViewStyleGrouped)];
        self.table.dataSource = self;
        self.table.delegate = self;
        [self.contentView addSubview:self.table];
  
        [self.table registerClass:[Thirdlub_routeTableViewCell class] forCellReuseIdentifier:@"cell1"];
    }
    return self;
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    self.table.frame = self.contentView.frame;
}

#pragma mark - 赋值方法
- (void)setClub_id:(NSString *)club_id
{
    [self prepareDiscussionData];
}
-(void)reloadData{
    [self.table reloadData];
}

#pragma mark - 准备线路活动数据
#pragma mark - 获取数据
- (void)prepareDiscussionData
{
    NSString *str = [NSString stringWithFormat:@"http://api.lis99.com/v2/club/topiclist/%@/1/?page=0?category=1&club_id=%@&page=0", self.club_id, self.club_id];
    
    [AFNetworkHandler getUrl:str cookie:nil result:^(id result) {
        self.rootArr = result[@"data"][@"topiclist"];
        [self.table reloadData];
    }];
}
#pragma mark - tableView协议方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.rootArr.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 200;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Thirdlub_routeTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    cell.title.text = self.rootArr[indexPath.row][@"title"];
    cell.times.text = self.rootArr[indexPath.row][@"times"];
    cell.catename.text = self.rootArr[indexPath.row][@"catename"];
    [cell.image sd_setImageWithURL:[NSURL URLWithString:self.rootArr[indexPath.row][@"image"][@"image"]]];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;//无选中颜色
    return cell;
    
}
#pragma mark - 点击
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    [self.delelgate RoJumpVC:self.rootArr[indexPath.row][@"id"]];
}





@end
